package cn.doways.api.utils;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList;


/**
 * @ClassName SmsUtils
 * @Description //TODO
 * @Author shellming
 * @Date 2019-08-10 22:45
 **/


public class SmsUtils {

    private final static int APPID = 1400240554;

    private final static String APPKEY = "fa25b306a42a3db48b51fbb320ad4611";

    private final static String NATIONAL_CODE ="86";

    private final static int TEMPLATE_ID= 392117;

    private final static String SMS_SIGN = "到位不到位网";

    public static String sender(String phoneNumber, ArrayList<String> params) {

        try {
            SmsSingleSender smsSingleSender = new SmsSingleSender(SmsUtils.APPID, SmsUtils.APPKEY);
            SmsSingleSenderResult result = smsSingleSender.sendWithParam(SmsUtils.NATIONAL_CODE, phoneNumber, SmsUtils.TEMPLATE_ID, params, SmsUtils.SMS_SIGN, "", params.get(0));
            System.out.println("短信发送：  "+result);
            return result.toString();
        } catch (HTTPException e) {
            return e.toString();
        } catch (JSONException e) {
            e.printStackTrace();
           return e.toString();
        } catch (IOException e) {
            return e.toString();
        }
    }

}
